from django.core.paginator import Paginator

def generate_page_bar(paginator,current_page):
    before = []
    after = []
    page = {}
    each_part_item_number = 4
        
    left_start_number = current_page-each_part_item_number
    if left_start_number<2:
        each_part_item_number = each_part_item_number + (2-left_start_number)
        left_start_number = 2 
    
    right_end_number = current_page+each_part_item_number-1
    if right_end_number>paginator.num_pages:
        if left_start_number>2:
            left_start_number = left_start_number - (right_end_number-(paginator.num_pages-1))
            if left_start_number<2:
                left_start_number = 2
        right_end_number = paginator.num_pages-1
    
    p = paginator.page(current_page)
    #put page number after current_page
    if p.has_next():        
        next_number = p.next_page_number()
        count = 0
        while next_number<=right_end_number:
            after.append(next_number)
            next_number = next_number + 1
            count = count + 1
        if right_end_number<paginator.num_pages-1:
            page['has_more_after'] = True
        else:
            page['has_more_after'] = False
        
    page['after'] = after
    #put page number before current_page
    if p.has_previous():           
        pre_number = left_start_number
        while pre_number<current_page :
            before.append(pre_number)
            pre_number = pre_number + 1
        if left_start_number > 2:
            page['has_more_before'] = True
        else:
            page['has_more_before'] = False
    page['before'] = before
      
    return page